<?php
$con = mysqli_connect("localhost", "root", "root", "gp23");
$username = $_GET["username"];
$password = $_GET["password"];
header("Access-Control-Allow-Origin:*");
$sql = "SELECT * FROM `login` WHERE `username`='$username' ";
$res = mysqli_query($con, $sql);
if (!$res) {
    die('{"type":"error", "msg" : "数据库错误" , "detail" : "' . mysqli_error($con) . '"}');
}
$arr = mysqli_fetch_all($res, MYSQLI_ASSOC);

if (count($arr) >= 1) {
    echo '{"type":"error", "msg" : "登陆成功成功"}';
} else {
    $sql1 = "INSERT INTO `login` VALUES ('$username','$password',null)";
    $res = mysqli_query($con, $sql1);
    if (!$res) {
        die("添加数据错误，错误信息：" . mysqli_error($con));
    }
    echo '{"type":"success", "msg" : "用户名或密码错误"}';
}
